//
//  FxInvestmentBasicParamsController.m
//  StrategyInspector
//
//  Created by jiro on 12/07/18.
//  Copyright 2012 jiro music. All rights reserved.
//

#import "FxInvestmentBasicParameterController.h"

#import "Constants.h"
#import "../Commons.h"

@implementation FxInvestmentBasicParameterController

- (void) windowDidLoad
{
	[ positionButton removeAllItems ];
	[ positionButton addItemWithTitle: InvestmentPosition::toString( InvestmentPosition::Type_Long ) ];
	[ positionButton addItemWithTitle: InvestmentPosition::toString( InvestmentPosition::Type_Short ) ];
	[ positionButton selectItemAtIndex: 0 ];

	[ currencyExchangeTypeButton removeAllItems ];
	for ( int i = 0; i < CurrencyExchange::Type_Count; i++ )
	{
		[ currencyExchangeTypeButton addItemWithTitle: CurrencyExchange::toString( ( CurrencyExchange::Type ) i ) ];
	}
	
	[ self valueInput: self ];
}

- (IBAction) valueInput: (id) sender
{
	FxInvestmentBasicParameterSet basicParam =  [ self parameter ];

	[ minimumTragetSettlementExchangeRateGap setDoubleValue: basicParam.getMinimumTargetSettlementExchangeGap() ];
	[ maximumLossCutExchangeRateGap setDoubleValue: basicParam.getMaximumLossCutExchangeGap() ];
	[ profitPerATradeAtTargetExchangeRate setDoubleValue: basicParam.getProfitPerTradeAtTargetExchange() ];
	[ lossPerATradeAtLossCutExchangeRate setDoubleValue: basicParam.getLossPerTradeAtLossCutExchange() ];
	[ breakEvenWinRate setDoubleValue: basicParam.getBreakEvenWinRate() ];
	[ targetWinRate setDoubleValue: basicParam.getTargetWinRate() ];
	[ breakEvenWinCount setDoubleValue: basicParam.getBreakEvenWinRate() * basicParam.getTradeCount() ];
	[ targetWinCount setDoubleValue: basicParam.getTargetWinRate() * basicParam.getTradeCount() ];
}

- (FxInvestmentBasicParameterSet) parameter
{
	NSMenuItem* menuItem = [ currencyExchangeTypeButton selectedItem ];
	FxInvestmentBasicParameterSet basicParam = FxInvestmentBasicParameterSet( 
		[ [ menuItem title ] substringWithRange: NSMakeRange( 0, 3 ) ],
		[ [ menuItem title ] substringWithRange: NSMakeRange( 4, 3 ) ],
		[ investMoney doubleValue ], 
		[ targetInterestRate doubleValue ], 
		[ tolerenceLossInterestRate doubleValue ], 
		[ leverage doubleValue ],
		[ entryExchangeRate doubleValue ],
		[ targetSettlementExchangeRateGap doubleValue ],
		[ lossCutExchangeRateGap doubleValue ],
		[ spread doubleValue ], 
		[ charge doubleValue ],
		[ tradeCount doubleValue ], 
		InvestmentPosition::toType( [ [ positionButton selectedItem ] title ] ) );
	return basicParam;
}

@end
